//
//  MessageViewController.swift
//  SwiftDemo
//
//  Created by 高冰 on 2020/10/14.
//

import UIKit

class MessageViewController: RootViewController {
    var titView: CilckTitleView?
    var cilckView: CilckPopView?

    override func viewDidLoad() {
        setupNavigtionBar()
        setPopView()
    }
}

extension MessageViewController {
    private func setupNavigtionBar() {
        let leftbutView: UIButton = UIButton()
        leftbutView.setImage(UIImage(named: "qp-xx-sel"), for: .selected)
        leftbutView.setImage(UIImage(named: "qp-xx"), for: .normal)
        leftbutView.sizeToFit()
        navigationItem.leftBarButtonItem = UIBarButtonItem(customView: leftbutView)

        titView = CilckTitleView()
        titView?.addTarget(self, action: #selector(onCilck), for: UIControl.Event.touchUpInside)

        navigationItem.titleView = titView
    }

    private func setPopView() {
        cilckView = CilckPopView(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: SCREEN_HEIGHT))
        cilckView?.isHidden = true
        cilckView?.toblock = { [weak self] (link: Int) in
            self?.onCilck()
            print(link)
        }
        view.addSubview(cilckView!)
    }

    @objc func onCilck() {
        titView?.isSelected = !titView!.isSelected
        print("点击了")
        if titView!.isSelected as Bool {
            cilckView?.isHidden = false
        } else {
            cilckView?.isHidden = true
        }
    }
}
